# Read in the data:
oil_spill <- read_sf(here("data", "oil_spill", "Oil_Spill_Incident_Tracking_%5Bds394%5D.shp")) %>% 
  clean_names()

ca_counties <- read_sf(here("data", "ca_counties", "CA_Counties_TIGER2016.shp"))

ca_subset <- ca_counties %>% 
  select(NAME, ALAND) %>% 
  rename(county_name = NAME, land_area = ALAND)

# Check CRS:
# ca_counties %>% st_crs()
# oil_spill %>%  st_crs()

1) Exploratory interactive map

# Set the viewing mode to interactive:
tmap_mode(mode = "view")
## tmap mode set to interactive viewing
# Make the map:
tm_shape(ca_subset) +
  tm_borders() +
  tm_shape(oil_spill) +
  tm_dots(col = "blue")

Static chloropleth map

#inland_oil_spill <- oil_spill %>% 
  #filter(inlandmari == "Inland") %>% 
  #group_by(localecoun) %>% 
  #count(localecoun)

# Join!
inland_spill_county <- ca_subset %>% 
  st_join(oil_spill)

inland_spill_counts <- inland_spill_county %>% 
  count(localecoun)

ggplot(data = inland_spill_counts) +
  geom_sf(aes(fill = n), color = "white", size = 0.1) +
  scale_fill_gradientn(colors = c("lightgray", "orange", "red")) +
  theme_minimal() +
  labs(fill = "Number of inland oil spills")